# -*- encoding: utf-8 -*-
"""
@Author: cuiyonghua
@CreateDate: 2021/8/9 6:14 下午
@File: appium_bilibili.py
@Description: 
"""
from appium import webdriver
from appium.webdriver.extensions.android.nativekey import AndroidKey


desired_caps = {
    'platformName': 'Android',
    'platformVersion': '6.0.1',
    'deviceName': 'Appium',  # 设备名，安卓手机可以随意填写
    'appPackage': 'tv.danmaku.bili',
    'appActivity': '.MainActivityV2',
    'unicodeKeyboard': True,  # 使用自带输入法，输入中文时填True
    'resetKeyboard': True,  # 执行完程序恢复原来输入法
    'noReset': True,  # 不要重置App
    'newCommandTimeout': 6000,
    'automationName': 'UiAutomator2',
    'udid': '127.0.0.1:5555',
}

driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desired_caps)
print(driver)
# 设置缺省等待时间
driver.implicitly_wait(5)
# 如果有青少年保护界面，点击我知道了
iknow = driver.find_elements_by_id("text3")
print(iknow)
if iknow:
    iknow.click()

# 根据id定位搜索位置框，点击
driver.find_element_by_id("expand_search").click()
# 根据id定位搜索输入框，点击
sbox = driver.find_element_by_id('search_src_text')
sbox.send_keys('爬虫')
# 输入回车键，确定搜索
driver.press_keycode(AndroidKey.ENTER)

# 选择（定位）所有视频标题
eles = driver.find_elements_by_id("title")
print(eles)

for ele in eles:
    print(ele.text)

input('**** Press to quit..')
driver.quit()




